import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Cangrejo here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Cangrejo extends Enemigo
{   
    int cont;
    int dir;
    public Cangrejo(){
      super();
      dir=-1;
      cont=0;
      
    }
    public Cangrejo(int di){
      super();
     
      dir=di;
      cont=0;
    }
    /**
     * Act - do whatever the Cangrejo wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        World w=getWorld();
        Actor c;
        move();
        if(isTouching(Bala.class)){
         c=getOneIntersectingObject(Bala.class);
         w.removeObject(c);
         salud-=((Bala)c).getDanio();
        }
        
        if(salud<=0){
         Caja a=new Caja();
         w.addObject(a,getX(),getY());
         w.removeObject(this);
         
        
        }
    }   
    
    public void move(){
         if(dir==-1) {
            setLocation(getX()-1,getY());
            cont++;
            if(cont==500){
              dir=1;
              cont=0;
            }
            }
         if(dir==1){
             setLocation(getX()+1,getY());
             cont++;
               if(cont==500){
                 dir=-1;
                 cont=0;
                }
                }
         
     }
}
